package com.cloud.report.api.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cloud.report.api.entity.ReportDataview;
import com.cloud.report.api.entity.ReportDataviewField;
import com.cloud.report.api.service.ReportDataViewService;
import com.cloud.report.common.result.Quokka;

@RestController
@RequestMapping("/report/api/dataview")
public class ReportDataviewController {

	@Autowired
	private ReportDataViewService reportDataViewService;
	
	@GetMapping("list")
	public Quokka listDataViewTree(){
		return new Quokka(true, reportDataViewService.listDataViewTree());
	}
	
	@GetMapping("detail")
	public Quokka showDataviewDetail(long id){
		return new Quokka(true, reportDataViewService.showDataviewDetail(id));
	}
	
	@PostMapping("saveupdate")
	public Quokka saveUpdate(@RequestBody ReportDataview dataview){
		return new Quokka(true, reportDataViewService.saveUpdateDataview(dataview));
	}
	
	@PostMapping("savefields")
	public Quokka saveUpdateDataFields(@RequestBody List<ReportDataviewField> fields, long id){
		return new Quokka(true, reportDataViewService.saveUpdateDataviewFields(id, fields));
	}
	
	@GetMapping("delete")
	public Quokka deleteDataView(long id){
		reportDataViewService.deleteDataview(id);
		return new Quokka(true);
	}
	
	@GetMapping("listtableviews")
	public Quokka listTableViews(String dsName){
		return new Quokka(true, reportDataViewService.listTableViews(dsName));
	}
	
}
